< previous page page_675 next page >

Page 675
Distances
This section contains formulas for calculating the distances between various objects. Module Distance.bas contains functions that return these distances. Example program Distance demonstrates these functions.
Point-to-Point
The distance between points A = (ax, ay, az) and B = (bx, by, bz) is written |AB|. This is the same as the length of the vector from A to B and is given by:
e10a6a0a59f035e870d90cca05b85fce.gif
|<bx - ax, by - ay, bz - az>| = 
Sqr((bx - ax)
2 + (by - ay)2 + (bz - az)2)
Point-to-Line
Suppose a line passes through point C = (cx, cy, cz) in the direction of the vector V = <vx, vy, vz>. Now consider a point P = (px, py, pz) as shown in Figure 19.6.
A is the vector from point C to point P. A' is the projection of vector A along vector P. The section Projection of a Vector onto a Vector earlier in this chapter showed that:
e10a6a0a59f035e870d90cca05b85fce.gif
|A'| = (A  V)/|V|
The shortest distance from point P to the line is along the vector A A' perpendicular to the line. That means the shortest distance from P to the line is |A A'|.
Then the Pythagorean theorem says:
e10a6a0a59f035e870d90cca05b85fce.gif
|A - A'| = Sqr(|A|2 - |A'|2) 
         = Sqr(|A|
2 - ((A  V)/|V|)2
z0695-01.gif
Figure 19.6
The shortest distance from point P
to a line is along the vector A  A'.

 
< previous page page_675 next page >